﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.NeighborUI {
    import flash.events.*;
    import flash.display.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.sim.*;
    import Display.*;
    import Display.aswingui.*;
    import Display.PopulationUI.*;

    public class CityHappinessPanel extends JPanel implements IPopulationStateObserver {

        protected var m_facePane:AssetPane;
        protected var m_faceAssets:Array;
        protected var m_happiness:int = 0;
        protected var m_animCount:int = 0;

        public function CityHappinessPanel(_arg1:LayoutManager=null){
            super(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 0, SoftBoxLayout.CENTER));
            this.m_faceAssets = [EmbeddedArt.nghbr_pop_good, EmbeddedArt.nghbr_pop_neutral, EmbeddedArt.nghbr_pop_bad];
            this.init();
            Global.world.citySim.addObserver(this);
        }
        protected function init():void{
            var _local1:Class = this.getFaceImage();
            this.m_facePane = new AssetPane((new (_local1)() as DisplayObject));
            this.m_happiness = Global.world.citySim.getHappinessState();
            this.appendAll(ASwingHelper.verticalStrut(1), this.m_facePane);
            ASwingHelper.prepare(this);
        }
        public function onPopulationInit(_arg1:int, _arg2:int, _arg3:int):void{
        }
        public function onPopulationChanged(_arg1:int, _arg2:int, _arg3:int, _arg4:int):void{
            var _local5:Class = this.getFaceImage();
            this.m_facePane.setAsset((new (_local5)() as DisplayObject));
            this.m_happiness = Global.world.citySim.getHappinessState();
        }
        public function animateIfHappinessChanged():void{
            var _local1:Object;
            if (this.m_happiness != Global.world.citySim.getHappinessState()){
                this.m_animCount = 10;
                this.m_happiness = Global.world.citySim.getHappinessState();
                _local1 = {alpha:0.3};
                _local1.onComplete = this.animationFinished;
                Z_TweenLite.to(this.m_facePane, 0.5, _local1);
            };
        }
        public function animationFinished():void{
            var _local1:Number;
            var _local2:Object;
            this.m_animCount--;
            if (this.m_animCount > 0){
                _local1 = ((this.m_animCount & 1)) ? 1 : 0.3;
                _local2 = {alpha:_local1};
                _local2.onComplete = this.animationFinished;
                Z_TweenLite.to(this.m_facePane, 0.5, _local2);
                return;
            };
        }
        public function onPotentialPopulationChanged(_arg1:int, _arg2:int):void{
        }
        public function onPopulationCapChanged(_arg1:int):void{
            var _local2:Class = this.getFaceImage();
            this.m_facePane.setAsset((new (_local2)() as DisplayObject));
        }
        protected function onMouseOver(_arg1:MouseEvent):void{
            if (!Global.ui.bNeighborActionsMenuOn){
                PopulationPopup.getInstance().show();
                _arg1.stopPropagation();
            };
        }
        protected function onMouseOut(_arg1:MouseEvent):void{
            PopulationPopup.getInstance().hide();
            _arg1.stopPropagation();
        }
        protected function getFaceImage():Class{
            var _local1:int = Global.world.citySim.getHappinessState();
            return (this.m_faceAssets[_local1]);
        }

    }
}//package Display.NeighborUI 
